#include "leecode.h"

#include <set>
#include <iostream>

using namespace std;

class Solution {
public:
    string convert(string s, int numRows) {
        int len = s.length();
        cout << "len is " << len << "  row is " << numRows << endl;
        if(numRows <= 1 || len <= numRows)
          return s;
        std::string ret;
        ret.resize(len);
        if(numRows == 2) {
            for(int i = 0; i < len; i+= 2)
              ret.push_back(s[i]);
            for(int i = 1; i < len; i+= 2)
              ret.push_back(s[i]);
        }

        int distance = 2 *numRows -2;
        int  x = len / distance;
        int y = len % distance;
        for(int i = 0; i < len; i = i+ distance) {
            ret.push_back(s[i]);
        }

        cout << "ret is 1 " << ret << endl;

        for(int i = 1; i < numRows - 1; i++) {
            int distance2 = 2 * (numRows - i  -1);
            for(int j = i; j < len ; ) {
                ret.push_back(s[j]);
                if(j + distance2 < len)
                   ret.push_back(s[j+distance2]);
                j = j + distance;
            }
        }

        cout << "ret is 2 " << ret << endl;

        for(int i = numRows - 1; i < len; i = i+ distance) {
            ret.push_back(s[i]);
        }
        cout << "ret is 100 " << ret << endl;
       return std::move(ret);
    }

    void expect(std::string input,  int numRows, std::string s) {
    std::string ret = convert(input, numRows);
    if(ret.compare(ret) == 0)
      printf("%s succeed\n", s.data());
    else
      printf("%s fail, ret is %s\n", s.data(), ret.data());
}
};

TEST(convert, converttest) {
  GTEST_SKIP();
    Solution s;
    s.expect("PAYPALISHIRING", 3, "PAHNAPLSIIGYIR");
    s.expect("PAYPALISHIRING", 4, "PINALSIGYAHRPI");
    s.expect("A", 1, "A");
}
